<?php

function formatTime($time){
    $rtime = date("m-d H:i",$time);
     $htime = date("H:i",$time);
     $time = time() - $time;
     if ($time < 60){
         $str = '刚刚';
     }elseif($time < 60 * 60){
         $min = ($time/60);
         $str = $min.'分钟前';
     }elseif($time < 60 * 60 * 24){
         $h = ($time/(60*60));
         $str = $h.'小时前 ';
     }elseif($time < 60 * 60 * 24 * 3){
         $d = ($time/(60*60*24));
         if($d==1){
             $str = '昨天 '.$rtime;
         }else{
             $str = '前天 '.$rtime;
         }
     }else{
         $str = $rtime;
     }
     return $str;
}

function date_huan($timestamp) {
    $seconds = time() - $timestamp;
    if($seconds > 31536000) {
        return date('Y-n-j',$timestamp);
    } elseif($seconds > 2592000) {
        return ceil($seconds / 2592000).'月前';
    } elseif($seconds > 86400) {
        return ceil($seconds / 86400).'天前';
    } elseif($seconds > 3600) {
        return ceil($seconds / 3600).'小时前';
    } elseif($seconds > 60) {
        return ceil($seconds / 60).'分钟前';
    } else {
        return $seconds.'秒前';
    }
}